#!/usr/bin/env python
# @FileName :4-8-homework-passwd.py
# @Time :2024/4/8 16:37
# @Author :pengyaqin
#密码复杂度验证

def Passwd(password):
    score = 2
    improve = []
    #查看长度
    if len(password) > 8:
        score += 1
    else:
        improve.append("密码长度不超过八位")
    #查看是否有三种以上的字符
    has_uppercase = any(char.isupper() for char in password)
    has_lowercase = any(char.islower() for char in password)
    has_digit = any(char.isdigit() for char in password)
    has_special = any(not char.isalnum() for char in password)
    char_type = sum((has_uppercase, has_lowercase, has_digit, has_special))
    if  char_type >= 3:
        score += 1
    else:
        improve.append("密码少于三种字符")
    #查看是否有长度大于等于三的重复子串
    score += 1
    for i in range(len(password)-2):
        for j  in range(i+3,len(password)+1):
            if password[i:i+3] == password[j:j+3]:
                improve.append("存在长度超过或等于三的重复子串")
                score -= 1
                break
    return score,improve
score,improve=Passwd(input("请设置密码："))
print(f"密码的等级评分为{score}")
print(f"需要改进的是{improve}")

